<!DOCTYPE html>
<html lang="en">
<style type="text/css">
    .tipinfo{display: none};
</style>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <link rel="shortcut icon" href="<!--{eval echo register_static('img/touch-icon-57x57.png');}-->">

    <title>粉粉管理系统</title>

    <!-- Bootstrap core CSS -->
    <link href="<!--{eval echo register_static('css/bootstrap.min.css');}-->" rel="stylesheet">
    <link href="<!--{eval echo register_static('css/bootstrap-reset.css');}-->" rel="stylesheet">

    <!--Animation css-->
    <link href="<!--{eval echo register_static('css/animate.css');}-->" rel="stylesheet">

    <!--Icon-fonts css-->
    <link href="<!--{eval echo register_static('assets/font-awesome/css/font-awesome.css');}-->" rel="stylesheet" />
    <link href="<!--{eval echo register_static('assets/ionicon/css/ionicons.min.css');}-->" rel="stylesheet" />

    <link href="<!--{eval echo register_static('assets/sweet-alert/sweet-alert.min.css');}-->" rel="stylesheet">

    <!-- Plugins css -->
    <link href="<!--{eval echo register_static('assets/modal-effect/css/component.css');}-->" rel="stylesheet">

    <!-- DataTables -->
    <link rel="stylesheet" href="<!--{eval echo register_static('assets/datatables/jquery.dataTables.min.css" rel="stylesheet');}-->" />

    <!-- Custom styles for this template -->
    <link href="<!--{eval echo register_static('css/style.css');}-->" rel="stylesheet">
    <link href="<!--{eval echo register_static('css/helper.css');}-->" rel="stylesheet">

    <!-- My styles for this template -->
    <link href="<!--{eval echo register_static('css/common.css');}-->" rel="stylesheet">
    <link href="<!--{eval echo register_static('assets/timepicker/bootstrap-timepicker.min.css');}-->" rel="stylesheet">
    <link href="<!--{eval echo register_static('assets/timepicker/bootstrap-datepicker.min.css');}-->" rel="stylesheet">

</head>

<body id="mybody">

<!-- Aside Start-->
<!--{template admin_v2/leftside}-->
<!-- Aside Ends-->


<!--Main Content Start -->
<section class="content">

    <!-- Header -->
    <!--{template admin_v2/header}-->
    <!-- Header Ends -->


    <!-- Page Content Start -->
    <!-- ================== -->

    <div class="wraper container-fluid diary-topics">

        <div class="row">
            <div class="col-md-12">
                <div class="panel panel-default" style="overflow: auto;">
                    <div class="panel-heading">
                        <h3 class="panel-title">活动广告列表</h3>
                    </div>
                    <div class="panel-body">
                        <div class="row" style="margin-bottom: 10px">
                            <div class="col-md-8 col-sm-8 col-xs-8">
                                <!-- Search -->
                                <div class="form-inline">
                                    <div style="display: inline-block; padding-right: 20px">筛选</div>
                                    <div class="form-group">
                                        <select class="form-control myChoose" name="type">
                                            <option value="no">类型(全部)</option>
                                            <option value="launch">开机页面</option>
                                            <option value="banner">社区Banner</option>
                                            <option value="home_banner">首页Banner</option>
                                            <option value="wisdom">每日一语</option>
                                            <option value="recommend_banner">推荐banner</option>
                                            <option value="homecat">首页猫</option>
                                            <option value="choicegroup">精选圈子</option>
                                        </select>
                                    </div>
                                    <div class="form-group">
                                        <select class="form-control myChoose" name="face">
                                            <option value="no">有效期(全部)</option>
                                            <option value="1">有效</option>
                                            <option value="0">无效</option>
                                        </select>
                                    </div>
                                    <div class="form-group">
                                        <select class="form-control myChoose" name="status">
                                            <option value="no">环境(全部)</option>
                                            <option value="0">正式</option>
                                            <option value="1">测试</option>
                                        </select>
                                    </div>
                                    <div class="form-group pageCon">

                                    </div>
                                </div>
                            </div>
                            <div class="col-md-4 col-sm-4 col-xs-4">
                                <button class="btn btn-info myAdd"><i class="ion-plus-round"></i> 新增</button>
                                <button class="btn btn-info myRebuild"><i class="ion-loop"></i> 刷新精选</button>
                                <button class="btn btn-info myDayRebuild"><i class="ion-loop"></i> 刷新每日一语</button>
                                <button class="btn btn-info myAddTest"><i class="ion-plus-round"></i> 新增测试</button>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-12 col-sm-12 col-xs-12">
                                <table id="datatable" class="table table-striped table-bordered table-hover">
                                    <thead>
                                    <tr>
                                        <th width="5%">类型</th>
                                        <th width="10%">名称/内容</th>
                                        <th>图片</th>
                                        <th>大图</th>
                                        <th width="10%">Action</th>
                                        <th>上线 / 下线</th>
                                        <th>排序</th>
                                        <th>有限期</th>
                                        <th>角色</th>
                                        <th>区间</th>
                                        <th>环境</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>

                                    <tbody id="tbody">

                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div class="row" style="margin-top: 15px">
                            <div class="form-group pageCon"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>
    <!-- Page Content Ends -->
    <!-- ================== -->

    <div id="con-close-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">

    </div><!-- /.modal -->


    <!-- Footer Start -->
    <!--{template admin_v2/footer}-->
    <!-- Footer Ends -->



</section>
<!-- Main Content Ends -->

<!--template start-->
<script type="text/template" id="tableCon">
    {{#.}}
    <tr>
        <td><label class="label label-success">{{{activityTypeNO2Text type}}}</label></td>
        <td><span style="font-size: 12px">标题:</span>{{{title}}}<br/><span style="font-size: 12px">内容:</span><span style="color: #df8505">{{{content}}}</span></td>
        <td><img src="{{{image_url}}}" width="100" class="showImg" /></td>
        <td><img src="{{{link_url}}}" width="100" class="showImg" style="{{{isWisdom type}}}" /></td>
        <td><label>{{{action_url}}}</label></td>
        <td><label class="label label-info">{{{dateConv start}}}</label> / <label class="label label-danger">{{{dateConv end}}}</label></td>
        <td>{{{sort}}}</td>
        <td>{{{activityTimeBeforeEnd end}}}</td>
        <td><label class="label label-success">{{{roleTypeNO2Text role}}}</label></td>
        <td><label class="label label-success">{{{quantumTypeNO2Text quantum}}}</label></td>
        <td><label class="label label-success">{{{showIsTest status}}}</label></td>
        <td>
            <div class="btn-group btn-group-sm">
                <button type="button" class="btn btn-danger myDelete" data-id="{{{id}}}">删除</button>
                <button type="button" class="btn btn-info myEdit" data-id="{{{id}}}" data-type="{{{type}}}" data-status="{{{status}}}">编辑</button>
            </div>
        </td>
    </tr>
    {{/.}}
</script>

<script type="text/template" id="editModal">
    {{#.}}
    <form>
        <div>
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th width="25%">类别</th>
                    <th width="75%">内容</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td>类型</td>
                    <td>
                        <select style="height: 26px;" name="type" id="onetype">
                            {{{activityTypeSelect type}}}
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>角色</td>
                    <td>
                        <select style="height: 26px;" name="role">
                            {{{roleTypeSelect role}}}
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>时间段</td>
                    <td>
                        <select style="height: 26px;" name="quantum">
                            {{{quantumTypeSelect quantum}}}
                        </select>
                    </td>
                </tr>
                <tr id="isTest">
                    <td>是否切换成正式</td>
                    <td>
                        <select style="height: 26px;" name="status">
                            {{{showIsTestSelect status}}}
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>图片链接</td>
                    <td>
                        <textarea class="form-control" rows="3" name="image_url">{{{image_url}}}</textarea>
                    </td>
                </tr>
                <tr id="bigimglink">
                    <td>大图/网页链接(<span style="color: red">仅每日一语/开机页面使用</span>)</td>
                    <td>
                        <textarea class="form-control" rows="3" name="link_url">{{{link_url}}}</textarea>
                    </td>
                </tr>
                <tr>
                    <td>Action</td>
                    <td>
                        <textarea class="form-control" rows="3" name="action_url">{{{action_url}}}</textarea>
                    </td>
                </tr>
                <tr>
                    <td>名称</td>
                    <td>
                        <input type="text" name="name" class="form-control" placeholder="" value="{{{name}}}">
                    </td>
                </tr>
                <tr>
                    <td>标题</td>
                    <td>
                        <input type="text" name="title" class="form-control" placeholder="" value="{{{title}}}">
                    </td>
                </tr>
                <tr>
                    <td>内容</td>
                    <td>
                        <textarea class="form-control" rows="3" name="content">{{{content}}}</textarea>
                    </td>
                </tr>
                <tr class="tipinfo">
                    <td>tip信息：名称</td>
                    <td>
                        <select style="height: 26px;" name="tip_title" id="tiptitle">
                            {{{tipTypeSelect tip_title}}}
                        </select>
                    </td>
                </tr>
                <tr style="display:none;">
                    <td>action</td>
                    <td>
                        <input type="text" name="tip_action" class="form-control" placeholder="" value="{{{tip_action}}}">
                    </td>
                </tr>
                <tr style="display:none;">
                    <td>bg</td>
                    <td>
                        <input type="text" name="tip_bg" class="form-control" placeholder="" value="{{{tip_bg}}}">
                    </td>
                </tr>
                <tr style="display:none;">
                    <td>bg</td>
                    <td>
                        <input type="text" name="tip_icon" class="form-control" placeholder="" value="{{{tip_icon}}}">
                    </td>
                </tr>
                <tr>
                    <td>显示时间</td>
                    <td >
                        <div class="form-inline">
                            <div class="form-group">
                                <label>开始:</label>
                                <input type="text" name="start" class="form-control timepicker2"  placeholder="" value="{{{dateConv start}}}" style="width: 180px">
                            </div>
                            <div class="form-group">
                                <label>结束:</label>
                                <input type="text" name="end" class="form-control timepicker2" placeholder="" value="{{{dateConv end}}}" style="width: 180px">
                            </div>
                        </div>
                    </td>
                </tr>

                <tr>
                    <td>排序</td>
                    <td>
                        <input type="number" name="sort" class="form-control" placeholder="" value="{{{sort}}}" style="width: 100px" min="0">
                    </td>
                </tr>
                <tr>
                    <td>操作</td>
                    <td style="text-align: center">
                        <button type="button" class="btn btn-danger myDelete" data-id="{{{id}}}">删除</button>&nbsp;&nbsp;&nbsp;&nbsp;
                        <button type="button" class="btn btn-info myEditPost" data-id="{{{id}}}">完成</button>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    </form>
    {{/.}}
</script>

<script type="text/template" id="addModal">
    <form>
        <div>
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th width="25%">类别</th>
                    <th width="75%">内容</th>
                </tr>
                </thead>
                <tbody>
                <tr style="display:none;">
                    <td>是否为测试数据</td>
                    <td>
                        <input type="text" name="status" class="form-control" value="{{{status}}}">
                    </td>
                </tr>
                <tr>
                    <td>类型</td>
                    <td>
                        <select style="height: 26px;" name="type" id="onetype">
                            {{{activityTypeSelect 'wisdom'}}}
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>角色</td>
                    <td>
                        <select style="height: 26px;" name="role">
                            {{{roleTypeSelect  '0'}}}
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>时间段</td>
                    <td>
                        <select style="height: 26px;" name="quantum">
                            {{{quantumTypeSelect  '0'}}}
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>图片链接</td>
                    <td>
                        <textarea class="form-control" rows="3" name="image_url"></textarea>
                    </td>
                </tr>
                <tr id="bigimglink">
                    <td>大图/网页链接(<span style="color: red">仅每日一语/开机页面使用</span>)</td>
                    <td>
                        <textarea class="form-control" rows="3" name="link_url"></textarea>
                    </td>
                </tr>
                <tr>
                    <td>Action</td>
                    <td>
                        <textarea class="form-control" rows="3" name="action_url">pinksns://group/topic?</textarea>
                    </td>
                </tr>
                <tr>
                    <td>名称</td>
                    <td>
                        <input type="text" name="name" class="form-control" placeholder="" value="">
                    </td>
                </tr>
                <tr>
                    <td>标题</td>
                    <td>
                        <input type="text" name="title" class="form-control" placeholder="" value="">
                    </td>
                </tr>
                <tr>
                    <td>内容</td>
                    <td>
                        <textarea class="form-control" rows="3" name="content"></textarea>
                    </td>
                </tr>
                <tr class="tipinfo">
                    <td>tip信息：名称</td>
                    <td>
                        <select style="height: 26px;" name="tip_title" id="tiptitle">
                            {{{tipTypeSelect 'morning'}}}
                        </select>
                    </td>
                </tr>
                <tr style="display:none;">
                    <td>action</td>
                    <td>
                        <input type="text" name="tip_action" class="form-control" placeholder="">
                    </td>
                </tr>
                <tr style="display:none;">
                    <td>bg</td>
                    <td>
                        <input type="text" name="tip_bg" class="form-control" placeholder="">
                    </td>
                </tr>
                <tr style="display:none;">
                    <td>bg</td>
                    <td>
                        <input type="text" name="tip_icon" class="form-control" placeholder="">
                    </td>
                </tr>
                <tr>
                    <td>显示时间</td>
                    <td >
                        <div class="form-inline">
                            <div class="form-group">
                                <label>开始:</label>
                                <input type="text" name="start" class="form-control timepicker2"  placeholder="" value="" style="width: 180px">
                            </div>
                            <div class="form-group endtimeinput">
                                <label>结束:</label>
                                <input type="text" name="end" class="form-control timepicker2" placeholder="" value="" style="width: 180px">
                            </div>
                        </div>
                    </td>
                </tr>

                <tr>
                    <td>排序</td>
                    <td>
                        <input type="number" name="sort" class="form-control" placeholder="" value="0" style="width: 100px" min="0">
                    </td>
                </tr>
                <tr>
                    <td>操作</td>
                    <td style="text-align: center">
                        <button type="button" class="btn btn-info myAddPost">完成</button>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    </form>
</script>


<script type="text/template" id="flushDayModal">
    <form>
        <div>
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th width="25%">类别</th>
                    <th width="75%">内容</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td>选择日期</td>
                    <td >
                        <div class="form-inline">
                            <div class="form-group">
                                <input type="text" name="day" class="form-control timepicker3"  placeholder="" value="" style="width: 200px">
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>操作</td>
                    <td style="text-align: center">
                        <button type="button" class="btn btn-info myFlushDayPost">确定</button>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    </form>
</script>
<!--template end-->


<!-- js placed at the end of the document so the pages load faster -->
<script src="<!--{eval echo register_static('js/jquery.js');}-->"></script>
<script src="<!--{eval echo register_static('js/bootstrap.min.js');}-->"></script>
<script src="<!--{eval echo register_static('js/pace.min.js');}-->"></script>
<script src="<!--{eval echo register_static('js/wow.min.js');}-->"></script>
<script src="<!--{eval echo register_static('js/jquery.nicescroll.js');}-->" type="text/javascript"></script>
<script src="<!--{eval echo register_static('js/jquery.app.js');}-->"></script>

<script src="<!--{eval echo register_static('js/handlebars-v4.0.5.js');}-->"></script>
<script src="<!--{eval echo register_static('js/handlebars-helper.js');}-->"></script>
<script src="<!--{eval echo register_static('layer/layer.js');}-->"></script>
<script src="<!--{eval echo register_static('laypage/laypage.js');}-->"></script>
<script src="<!--{eval echo register_static('laydate/laydate.js');}-->"></script>

<script src="<!--{eval echo register_static('assets/datatables/jquery.dataTables.min.js');}-->"></script>
<script src="<!--{eval echo register_static('assets/datatables/dataTables.bootstrap.js');}-->"></script>
<script src="<!--{eval echo register_static('assets/sweet-alert/sweet-alert.min.js');}-->"></script>
<script src="<!--{eval echo register_static('assets/sweet-alert/sweet-alert.init.js');}-->"></script>

<!-- Modal-Effect -->
<script src="<!--{eval echo register_static('assets/modal-effect/js/classie.js');}-->"></script>
<script src="<!--{eval echo register_static('assets/modal-effect/js/modalEffects.js');}-->"></script>

<script type="text/javascript">
    $(document).ready(function() {
        var tipDataInfo = {
            'tipActionVal' : {
                'morning':'pinksns://diarytopic/detail?topicid=206146',
                'ylmqq':'pinksns://diarytopic/detail?topicid=208200',
                'jrbd':'pinksns://diarytopic/detail?topicid=208201',
                'msnbs':'pinksns://diarytopic/detail?topicid=208202',
                'wafm':'pinksns://diarytopic/detail?topicid=208203',
            },
            'tipBgVal' : {
                'morning':'http://d.fenfenriji.com/web/static/index_topic/index_read_ffzb.png',
                'ylmqq':'http://d.fenfenriji.com/web/static/index_topic/index_read_ylmqq.png',
                'jrbd':'http://d.fenfenriji.com/web/static/index_topic/index_read_jrbd.png',
                'msnbs':'http://d.fenfenriji.com/web/static/index_topic/index_read_msnbs.png',
                'wafm':'http://d.fenfenriji.com/web/static/index_topic/index_read_fm.png',
            },
            'tipIconVal' : {
                'morning':'http://d.fenfenriji.com/web/static/index_topic/icon_ffzb.png',
                'ylmqq':'http://d.fenfenriji.com/web/static/index_topic/icon_ylmqq.png',
                'jrbd':'http://d.fenfenriji.com/web/static/index_topic/icon_jrbd.png',
                'msnbs':'http://d.fenfenriji.com/web/static/index_topic/icon_msnbs.png',
                'wafm':'http://d.fenfenriji.com/web/static/index_topic/icon_fm.png',
            },
        };
        //编译模板
        var tp_tableCon = Handlebars.compile($('#tableCon').html());
        var tp_editModal = Handlebars.compile($('#editModal').html());
        var tp_addModal = Handlebars.compile($('#addModal').html());
        var tp_flushDayModal = Handlebars.compile($('#flushDayModal').html());

        var mydate = new Date();
        var year = mydate.getFullYear();
        var month = mydate.getMonth() + 1;
        var day = mydate.getDate() + 1;
        if(month<=9){
            month = '0' + month;
        }
        if(day<=9){
            day = '0' + day;
        }
        var tomorrow = year + '-' + month + '-' + day;

        $('.myChoose').change(function () {
            _Where_.page = 1;
            var name = $(this).attr('name');
            switch (name){
                case 'type':
                    $(this).val() != 'no' ?  _Where_.type = $(this).val() : _Where_.type = undefined;
                    break;
                case 'face':
                    $(this).val() != 'no' ?  _Where_.face = $(this).val() : _Where_.face = undefined;
                    break;
                case 'status':
                    $(this).val() != 'no' ?  _Where_.status = $(this).val() : _Where_.status = undefined;
                    break;
            }
            RequestList();
        });

        $('.myAdd').click(function () {
            var obj = new Object(); 
            obj.status = 0;
            var html = tp_addModal(obj);
            layer.open({
                type: 1,
                title: '新增',
                closeBtn: 1,
                area:['40%', '80%'],
                shadeClose: true,
                content: html
            });
        });

        $('.myAddTest').click(function () {
            var obj = new Object(); 
            obj.status = 1;
            var html = tp_addModal(obj);
            layer.open({
                type: 1,
                title: '新增测试数据',
                closeBtn: 1,
                area:['40%', '80%'],
                shadeClose: true,
                content: html
            });
        });
        var index = 0;
        $(document).off('change', 'form select[name="type"]').on('change', 'form select[name="type"]', function () {
            var val = $('form select[name="type"]').find("option:selected").val();
            var form = $('form select[name="type"]').parents('form');

            index++;
            if(val == 'choicegroup'){
                data = "<span class='inputHide_"+ index +"'><input type='text' placeholder='输入圈子Id' style='width:78px;margin-left:5px;margin-right:5px' name='bodyId'><button style='height: 26px;' class='btn-info btn-xs typeChange' type='button'>获取信息</button></span>";
            }else{
                data = "<span class='inputHide_"+ index +"'><input type='text' placeholder='输入BodyId' style='width:78px;margin-left:5px;margin-right:5px' name='bodyId'><button style='height: 26px;' class='btn-info btn-xs typeChange' type='button'>获取信息</button></span>";
            }
            $(this).after(data);
            $('.inputHide_' + index).nextAll().remove();
            $("input[name='bodyId']").val('');

            if (val=='wisdom' || val=='launch'){
                //form.find('.endtimeinput').hide();
                form.find('#bigimglink').show();
            }else{
                //form.find('.endtimeinput').show();
                form.find('#bigimglink').hide();
            }
            if(val=='recommend_banner'){
                form.find('.tipinfo').show();
            }else{
                form.find('.tipinfo').hide();
            }
        });
        //获取bodyId的详情
        $(document).on("click",".typeChange",function(e){
            var bodyId = $("input[name='bodyId']").val();
            var type = $("#onetype").select().val();
            if(type == 'choicegroup'){
                $.post(
                    '/admin.php?ac=activity2&op=getGroupInfo',
                    {gid:bodyId},
                    function (r) {
                        if(r._code == 1){
                            strHtml(r.result);
                        }else{
                            layer.msg(r._msg, {icon: 0});
                        }
                    }
                );
            }else {
                $.post(
                    '/admin.php?ac=activity2&op=getDiaryInfoByBodyId',
                    {bodyId: bodyId},
                    function (r) {
                        if (r._code == 1) {
                            strHtml(r.result);
                        } else {
                            layer.msg(r._msg, {icon: 0});
                        }
                    }
                );
            }
        });
        //填充数据
        function strHtml(d) {
            var val = $('form select[name="type"]').find("option:selected").val();
            var form = $('form select[name="type"]').parents('form');
            if(val=='recommend_banner'){
                if((typeof(d.article.url_type) == "undefined")){
                    var action = 'pinksns://diary/info?uid=' + d.listInfo.uid + '&bodyId=' + d.listInfo.bodyId;
                }else{
                    var action = 'pinksns://article/info?aid=' + d.article.url_type_id + '&author_uid=' + d.article.url_type_uid;
                }
                $('[name=start]').attr('value', tomorrow + ' 6:00:00');
                $('[name=end]').attr('value', tomorrow + ' 23:59:59');

                $('form textarea[name="action_url"]').html(action);
            }
            if(val=='banner'){
                if((typeof(d.article.url_type) == "undefined")){
                    var action = 'pinksns://group/topic?tid=1810707&uid=' + d.listInfo.uid + '&gid=16';
                }else{
                    var action = 'pinksns://article/info?aid=' + d.article.url_type_id + '&author_uid=' + d.article.url_type_uid;
                }
                $('form textarea[name="action_url"]').html(action);
            }
            if(val == 'choicegroup'){
                var action = 'pinksns://group/info?gid=' + d.group_info.gid;
                var image_url = d.group_info.cover;

                $('form textarea[name="action_url"]').html(action);
                $('form textarea[name="image_url"]').html(image_url);
            }

            //文章
            if(d.article){
                var image_url = 'http://img.fenfenriji.com' + d.article.url_image;
                $('form textarea[name="image_url"]').html(image_url);
            }
            //判断是否有图片链接，多张图片只选取第一张
            if(d.attachment) {
                var image_url = 'http://img.fenfenriji.com' + d.attachment[0].attachmentPath;
                $('form textarea[name="image_url"]').html(image_url);
            }
            //判断是否有内容
            if(d.bodyInfo.content)
            {
                var content = d.bodyInfo.content;
                content = content.replace(/\s/g,""); //去空格
                content = content.substring(0,50);   //截取50个字符
                $('form textarea[name="content"]').html(content);
            }
        }

        $(document).off('change', 'form select[name="tip_title"]').on('change', 'form select[name="tip_title"]', function () {
            var val = $(this).find("option:selected").val();
            
            $('[name=end]').attr('value', tomorrow + ' 23:59:59');
            if (val=='morning'){
                $('[name=start]').attr('value', tomorrow + ' 6:00:00');
            }else if(val=='ylmqq'){
                $('[name=start]').attr('value', tomorrow + ' 10:00:00');
            }else if(val=='jrbd'){
                $('[name=start]').attr('value', tomorrow + ' 13:00:00');
            }else if(val=='msnbs'){
                $('[name=start]').attr('value', tomorrow + ' 16:00:00');
            }else if(val=='wafm'){
                $('[name=start]').attr('value', tomorrow + ' 20:00:00');
            }
        });

        $(document).off('click', '.myDelete').on('click', '.myDelete', function () {
            var id = $(this).data('id');

            layer.confirm('确定删除？', {icon: 3, title:'提示'}, function(i){
                var index = layer.load();
                $.post(
                        '/admin.php?ac=activity2&op=delete&id=' + id,
                        function (r) {
                            layer.close(index);
                            if(r._code == 1){
                                layer.closeAll();
                                RequestList();
                                layer.msg('已删除', {icon: 1});
                            }else{
                                layer.msg(r._msg, {icon: 0});
                            }
                        }
                );
            });
        });
        var actionData="";
        $(document).on('blur','form textarea[name="action_url"]',function(){
           actionData=$(this).val();
        });
        $(document).off('click', '.myAddPost').on('click', '.myAddPost', function () {
            if(!actionData){
                actionData=$('form textarea[name="action_url"]').text();
            }
            var checkRes = checkAction(actionData);
            if(!checkRes){
                layer.alert('action有误!');
                return 0;
            }
            var type = $("#onetype").val()
            if(type != "recommend_banner"){
                $("[name^='tip_']").val("");
            }else{
                var tiptitle = $("#tiptitle").val();
                var tipAction = tipDataInfo.tipActionVal[tiptitle];
                var tipBg = tipDataInfo.tipBgVal[tiptitle];
                var tipIcon = tipDataInfo.tipIconVal[tiptitle];
                $('[name=tip_action]').attr('value',tipAction);
                $('[name=tip_bg]').attr('value',tipBg);
                $('[name=tip_icon]').attr('value',tipIcon);
            }
            
            var form = $(this).parents('form');
            var param = form.serialize();
            var types = form.find('[name="type"]').find("option:selected").text();

            layer.confirm('确定添加 <b>'+types+'</b> ？', {icon: 3, title:'提示'}, function(i){
                var index = layer.load();
                $.post(
                        '/admin.php?ac=activity2&op=add',
                        param,
                        function (r) {
                            layer.close(index);
                            if(r._code == 1){
                                layer.closeAll();
                                RequestList();
                                layer.msg('添加成功', {icon: 1});
                            }else{
                                layer.msg(r._msg, {icon: 0});
                            }
                        }
                );
            });
        });

        $(document).off('click', '.myRebuild').on('click', '.myRebuild', function () {
            layer.confirm('确定重新刷新精选？<br/>提示：你需要在自己电脑的host加上<br/> 112.124.20.101&nbsp;&nbsp;&nbsp;tips.ffrj.net 才能生效', {icon: 3, title:'提示'}, function(i){
                layer.load();
                layer.open({
                    type: 2,
                    title: '',
                    shadeClose: true,
                    closeBtn: 0,
                    shade: 0,
                    area: ['0px','0px'],
                    content: 'http://tips.ffrj.net/banner/create' //iframe的url
                });
                setTimeout(function () {
                    layer.closeAll();
                    layer.msg('操作成功');
                }, 1000);
            });
        });

        $(document).off('click', '.myDayRebuild').on('click', '.myDayRebuild', function () {
            var html = tp_flushDayModal();
            layer.open({
                type: 1,
                title: '编辑消息',
                closeBtn: 1,
                area:['400px', '300px'],
                shadeClose: true,
                content: html
            });
        });

        $(document).off('click', '.myFlushDayPost').on('click', '.myFlushDayPost', function () {
            var dates = $(this).parents('form').find('input[name="day"]').val().trim();
            if (!dates)return;
            layer.load();
            $.post(
                    '/admin.php?ac=activity2&op=flushday',
                    {dates:dates},
                    function (r) {
                        layer.closeAll();
                        if(r._code == 1){
                            RequestList();
                            layer.msg('更新成功', {icon: 1});
                        }else{
                            layer.msg(r._msg, {icon: 0});
                        }
                    }
            );

        });

        $(document).off('click', '.myEditPost').on('click', '.myEditPost', function () {
            if(!actionData){
                actionData=$('form textarea[name="action_url"]').text();
            }
            var checkRes = checkAction(actionData);
            if(!checkRes){
                layer.alert('action有误!');
                return 0;
            }
            var id = $(this).data('id');
            var type = $("#onetype").val();
            if(type != "recommend_banner"){
                $("[name^='tip_']").val("");
            }else{
                var tiptitle = $("#tiptitle").val();
                var tipAction = tipDataInfo.tipActionVal[tiptitle];
                var tipBg = tipDataInfo.tipBgVal[tiptitle];
                var tipIcon = tipDataInfo.tipIconVal[tiptitle];
                $('[name=tip_action]').attr('value',tipAction);
                $('[name=tip_bg]').attr('value',tipBg);
                $('[name=tip_icon]').attr('value',tipIcon);
            }

            layer.load();
            var param = $(this).parents('form').serialize();

            $.post(
                    '/admin.php?ac=activity2&op=editdetail&id=' + id,
                    param,
                    function (r) {
                        layer.closeAll();
                        if(r._code == 1){
                            RequestList();
                            layer.msg('更新成功', {icon: 1});
                        }else{
                            layer.msg(r._msg, {icon: 0});
                        }
                    }
            );

        });

        $(document).off('click', '.myEdit').on('click', '.myEdit', function () {
            var id = $(this).data('id');
            var type = $(this).data('type');
            var status = $(this).data('status');
            
            var index = layer.load();
            $.post(
                    '/admin.php?ac=activity2&op=msgdetail',
                    {id:id},
                    function (r) {
                        layer.close(index);
                        if(r._code == 1){
                            var html = tp_editModal(r.result);
                            layer.open({
                                type: 1,
                                title: '编辑消息',
                                closeBtn: 1,
                                area:['40%', '80%'],
                                shadeClose: true,
                                content: html
                            });
                        }else{
                            layer.msg(r._msg, {icon: 0});
                        }
                        if(type == 'recommend_banner'){
                            $('.tipinfo').show();
                        }
                        if(type != 'wisdom' && type !='launch'){
                            $('#bigimglink').hide();
                        }
                        if(status == 0){
                            $('#isTest').hide();
                        }
                    }
            );

        });

        $(document).off('click', '.timepicker2').on('click', '.timepicker2', function () {
            laydate({
                format: 'YYYY-MM-DD hh:mm:ss',
                istime: true
            });
        });

        $(document).off('click', '.timepicker3').on('click', '.timepicker3', function () {
            laydate({
                format: 'YYYYMMDD',
                festival: true,
                istime: false
            });
        });

        $(document).off('click', '.showImg').on('click', '.showImg', function () {
            layer.tips('<img src="'+$(this).attr('src')+'" />', $(this), {
                tips: [2, '#fff'],
            });
        });

        $(document).off('change', '.actionChange').on('change', '.actionChange', function () {
            var NO = $(this).val();
            ActionChangeSelect(NO);
        });

        _Where_ = {page:1};
        //请求数据列表数据
        var RequestList = function () {
            where = _Where_;
            if(typeof where == 'undefined')where = {};
            var index = layer.load();
            $.post(
                    '/admin.php?ac=activity2&op=list',
                    where,
                    function (r) {
                        if (r._code == 1){
                            var html = tp_tableCon(r.result);
                            $('#tbody').html(html);
                            laypage({
                                cont: $('.pageCon'), //容器。值支持id名、原生dom对象，jquery对象。【如该容器为】：<div id="page1"></div>
                                pages: 100, //通过后台拿到的总页数
                                curr: _Where_.page || 1, //当前页
                                jump: function(obj, first){ //触发分页后的回调
                                    if(!first){ //点击跳页触发函数自身，并传递当前页：obj.curr
                                        _Where_.page = obj.curr;
                                        RequestList();
                                    }
                                }
                            });
                        }else{
                            layer.msg(r._msg, {icon: 0});
                        }
                        layer.close(index);
                    }
            );
        }
        RequestList();

    });
    function checkAction(aa){
        return true;
        console.log(aa);
        var bb="pinksns://diary/info?";
        if(aa.indexOf(bb)!=-1){
            var check = true;
            var cc=aa.substr(bb.length);
            var dd=cc.split("&");
            for(var val in dd){
                if(dd[val].indexOf("bodyId")!=-1||dd[val].indexOf("uid")!=-1){
                    check = true;
                }else{
                    check = false;
                    break;
                }
            }
            return check;
        }

        var bbb="pinksns://group/topic?";
        if(aa.indexOf(bbb)!=-1){
            var check = true;
            var cc=aa.substr(bb.length);
            var dd=cc.split("&");
            console.log(dd);
            for( val in dd){
                if(dd[val].indexOf("tid")!=-1||dd[val].indexOf("uid")!=-1 || dd[val].indexOf("gid")!=-1){
                    check = true;
                }else{
                    check = false;
                    break;
                }
            }
            return check;
        }
        return true;
    }
</script>
</body>
</html>
